import com.opdar.athena.base.MessageType;

import java.io.IOException;
import java.net.Socket;
import java.nio.ByteBuffer;

/**
 * Created by shiju on 2017/7/4.
 */
public class HeartRunnable implements Runnable {
    private Socket socket;
    private byte[] project;

    public HeartRunnable(Socket socket, byte[] project) {
        this.project = project;
        this.socket = socket;
    }

    @Override
    public void run() {
        ByteBuffer buffer = ByteBuffer.allocate(project.length + 18);
        buffer.put(project);
        buffer.putInt(1);
        buffer.putShort((short) MessageType.HEARTBEAT);
        buffer.putInt(8);
        buffer.putLong(System.currentTimeMillis());
        try {
            socket.getOutputStream().write(buffer.array());
            socket.getOutputStream().flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
